package com.anycl.customer.controller;

import com.anycl.customer.entity.Customer;
import com.anycl.customer.exception.CustomerException;
import com.anycl.customer.service.CustomerService;
import com.anycl.customer.vo.CustomerResponse;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    private final CustomerService customerService;

    public CustomerController(CustomerService customerService) {
        this.customerService = customerService;
    }

    @PostMapping("/create")
    public CustomerResponse createCustomer(@RequestBody Customer customer, HttpSession session) throws CustomerException {
        return customerService.createCustomer(customer, session);
    }

    @PostMapping("/remove")
    public CustomerResponse removeCustomer(String id, HttpSession session) throws CustomerException {
        return customerService.removeCustomer(id, session);
    }

    @PostMapping("/update")
    public CustomerResponse updateCustomer(Customer customer, HttpSession session) throws CustomerException {
        return customerService.updateCustomer(customer, session);
    }

    @GetMapping("/get")
    public Customer getCustomer(String id, HttpSession session) throws CustomerException {
        return customerService.getCustomer(id, session);
    }

    @GetMapping("/getAll")
    public List<Customer> getCustomerList(HttpSession session) throws CustomerException {
        return customerService.getCustomerList(session);
    }
}
